package com.example.demo;

import com.example.demo.utils.EmbeddedImageEmailUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * HttpTest.
 *
 * @author blinkfox on 2017-06-28.
 * @version 1.0
 */
public class InlineImageEmailTester {

    public static void main(String[] args) throws IOException {
        String host="smtp.exmail.qq.com";
        String port="465";
        String mailFrom="lijing1@wxchina.com";
        String password="Wuxia7403";

        // message info
        String mailTo = "740393778@qq.com,1578321638@qq.com";
        String subject = "Test e-mail with inline images";
        StringBuffer body
                = new StringBuffer("<html>This message contains two inline images.<br>");
        body.append("The first image is a chart:<br>");
        body.append("<img src=\"cid:image1\" width=\"30%\" height=\"30%\" /><br>");
        body.append("The second one is a cube:<br>");
        body.append("<img src=\"cid:image2\" width=\"15%\" height=\"15%\" /><br>");
        body.append("End of message.");
        body.append("</html>");


        // inline images  a.jpg
        Map<String, String> inlineImages = new HashMap<String, String>();
        inlineImages.put("image1", "/Users/lijin/wuxia/temp/day0422/b.jpeg");
        inlineImages.put("image2", "/Users/lijin/wuxia/temp/day0422/a.jpg");

        try {
            EmbeddedImageEmailUtil.send(host, port, mailFrom, password, mailTo,
                    subject, body.toString(), inlineImages);
            System.out.println("Email sent.");
        } catch (Exception ex) {
            System.out.println("Could not send email.");
            ex.printStackTrace();
        }


    }

}
